package com.example.shiXun.dao;

import com.example.shiXun.domain.SysUser;
import com.example.shiXun.dto.UserDto;
import org.apache.ibatis.annotations.*;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ：meet
 * @date ：Created in 2020/4/11 16:27
 */
@Mapper
public interface UserDao {

    @Select("select * from sys_user t where t.username=#{username}")
    SysUser getUser(String username);


    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into sys_user(username, password, nickname, headImgUrl, phone, telephone, email, birthday, sex, status, createTime, updateTime) values(#{username}, #{password}, #{nickname}, #{headImgUrl}, #{phone}, #{telephone}, #{email}, #{birthday}, #{sex}, #{status}, now(), now())")
    int save(SysUser user);

    @Select("select * from sys_user t order by t.id limit #{startPosition},#{limit}")
    List<SysUser> getAllUsersByPage(@Param("startPosition") Integer startPosition, @Param("limit") Integer limit);


    @Select("select count(*) from sys_user t")
    Long countAllUsers();


    @Select("select * from sys_user t where t.telephone = #{telephone}")
    SysUser getUserByPhone(String telephone);

    @Select("select * from sys_user t where t.email=#{email}")
    SysUser getUserByEmail(String email);

    @Select("select * from sys_user t where t.id = #{id}")
    SysUser getUserById(Long id);

    void updateUser(SysUser sysUser);

    @Delete("delete from sys_user where id = #{userId}")
    int deleteUserById(int userId);

    @Select("select count(*) from sys_user where username like '%${username}%'")
    Long getUserByFuzzyUsername(@Param("username") String username);

    @Select("select * from sys_user where username like '%${username}%' limit #{startPosition}, #{limit}")
    List<SysUser> getUserByFuzzyUsernameAndPage(@Param("username") String username, @Param("startPosition") Integer offset, @Param("limit") Integer limit);
}
